Debbie Dickerson
Macromedia
Previous Columns
- ColdFusion MX for JRun 4 and Mac OS X
by Christian Cantrell - Macromedia Flash Detection Kit
by Fred Sharples - Simplicity Is Just The Start Of It
by Ben Forta - ColdFusion MX and Databases
by Debbie Dickerson - DRK 3 and Data Connection Kit
by Mike Chambers - Flashforward 2003
by Mike Chambers - Rich Internet Applications Come of Age
by Tom Hale - Dreamweaver MX: Supporting the PHP and ASP.NET Application Server Platforms
by George Fox - Now Announcing DevNet Subscriptions, Studio MX Plus, and FreeHand MX
by Ed Krimen - The Rich Media Advertising Development Center
by Suzanne Mattis - Macromedia Expands JRun and ColdFusion MX for J2EE to the Macintosh OS X Platform
by Christian Cantrell - Experience Matters
by Al Ramadan - Introducing Director MX
by Miriam Geller - Selling management on Rich Internet Applications
by Roger Murff - The end of hassles
by Eric Larsen - DevCon 2002 wrap-up
by Tom Hale - Experience: Can you bottle it?
by Michael Gough - The Macromedia anti-piracy program
by Steve Wozniak - Certification: Stand out from the crowd
by Tiffany Beltis - ColdFusion MX for J2EE
by Tom Hale - Introducing the Macromedia Developer Resource Kit
by Mike Chambers - Securing your web applications
by Vernon Viehe - The Answers Panel: Your lifeline to Macromedia
by Ana Dujmovic - DevCon 2002: Architecting a new Internet experience
by Greg Stern - Tips Library: Finding the "better way"
by Mimi Rosenheim - Which edition of Macromedia Flash Communication Server MX do I need?
by Mike Chambers - The future of Macromedia Flash on Devices
by Mike Chambers - Introducing Pet Market
by Steve Petersen - Get in touch with us
by Craig Goodman - Blogs are huge
by Ed Krimen - Macromedia MX, the future is already here
by Tom Hale - What's up in the Macromedia Flash MX world?
by Mike Chambers - What server language should I use?
by Matt Brown - Macromedia Flash MX favorite feature
by Mike Chambers - Macromedia Flash MX: New product, more power
by Tom Hale - Why you should care about XML
by Mike Chambers - Rapid development with extensions
by Matt Brown
ColdFusion MX and Databases
"Cold Fusion provides a simple, powerful and flexible way of developing dynamic, database-driven web sites without the need for sophisticated programming." No, I didn't forget to run my spell checker. This quote comes from an Allaire website archive, back in the days when it was spelled "Cold Fusion."
It's amazing to consider, given the amount of change that ColdFusion has gone through since its conception, that the ability to easily connect to and work with databases is still one its greatest features. And since the content for this DevNet launch is all about databases, it's a good time to talk about the various aspects involved in using databases with ColdFusion.
Getting Started
A good place to start is here in DevNet,
with the Database
Topic Center and the Get
Started with ColdFusion MX page. Whether
you're new to databases or just to ColdFusion,
there are several articles that explain
why you might want to have a dynamic web
site and how to get started.
Also helpful are the various tutorials within the Support Centers. The Wildlife Project, for instance, teaches you how to plan, design, create, and deploy a fully-functional website using Studio MX. And, if you're looking for a more traditional approach, we have books from Macromedia Press, online product courses through the Macromedia University, and instructor-led classes from our Authorized Training Partners.
ODBC or JDBC?
Historically, ODBC was the most prevalent
method of connecting to a database in ColdFusion.
When Macromedia introduced ColdFusion MX
on the Java platform, JDBC became the primary
way to connect ColdFusion to a database.
JDBC is the Java API that ColdFusion uses
to execute SQL statements and is available
in 4
types. ColdFusion MX comes with JDBC
type 4 drivers from DataDirect for the most
popular databases. But even if ColdFusion
MX doesn't include a type 4 driver for your
particular database, you can typically get
them from a database vendor. Use them whenever
possible! To find a driver for your database,
visit industry.java.sun.com/products/jdbc/drivers
or your database vendor website.
Two other options are also available, the DataDirect SequeLink ODBC Socket Server and the Sun JDBC-ODBC bridge. Use these only when you cannot use a type 4 JDBC driver, such as with MS Access data sources (or similar file-based databases) or SQL Server data sources, which require Trusted Connections. The JDBC-ODBC bridge is a type 1 driver, which means it must translate all JDBC calls into ODBC calls and then send them to the ODBC driver. Type 1 drivers perform below par, especially since it is not multi-threaded, and can even cause the Java Virtual Machine to fail if many connections overlap. We recommend that you use the JDBC-ODBC Bridge driver to prototype apps or when no other JDBC technology-based drivers exist.
The SequeLink ODBC Socket Server is a type 3 driver, which translates JDBC calls into the middle-tier server, in this case, the SequeLink Server. Although this is certainly preferable over a type 1 driver implementation, it still falls short of a type 4 driver. Since a type 3 driver relies on a separate server component, it introduces an additional area where problems may occur, such as failure of the "ColdFusion MX ODBC Server" service, which is the service that provides ODBC access through the Sequelink Server.
Connecting to your database
Now that you've decided which technology
and driver type to use, the next step is
to configure your data source. Where should
you go for help? Jonathan Quint covers connecting
to a database in ColdFusion in his new DevNet
article, Connecting
to Databases in ColdFusion MX . The
manuals are also an excellent source of
information. If you prefer the electronic
version, check out livedocs.macromedia.com,
especially since you can see comments that
have been submitted regarding the documentation.
The instructions vary based on the version
and edition of ColdFusion, so be sure to
pick the appropriate Data Source Management
section for your installation. There are
also TechNotes within the ColdFusion
Support Center that cover installation
of other popular drivers, such as the Oracle
JDBC thin driver or the Sybase
jConnect 5.5 driver.
So you've created your data source and now you're getting the dreaded "Connection verification failed for data source" message. What now? First, install ColdFusion MX Updater 3 if you haven't already done so. Prior to Updater 3, the error message always indicated that you should check the database username and password, regardless of the true nature of the error. Aside from the other bug fixes in the updater, you'll also get a newer set of DataDirect JDBC drivers, which could save you grief later in the process, when you actually start using your database!
Armed with the real cause of the connection failure, you can begin to work through the issue. The ColdFusion Support Center includes a number of TechNotes to help you through this process. For instance, check out TechNotes for troubleshooting data sources and database connectivity for Windows platforms and Unix platforms. A more comprehensive list is available under the Database section of the Testing and Troubleshooting page in the ColdFusion Support Center.
cfquery and Beyond
Most likely, cfquery will be
your first method of accessing your database.
You may find, however, that the basic cfquery
tag doesn't meet all of your application
needs. In this week's DevNet launch, Sue
Hove, director of instructor readiness at
Macromedia writes about Building
Advanced Queries in ColdFusion MX, explaining
the finer points of cfquery,
such as nesting query output, using cfdump
to display data structures, grouping and
filtering query results, querying a query,
and query caching.
Other options you might want to explore include stored procedures and transactions. Sam Neff discusses the advantages of stored procedures in his article, Learning Stored Procedure Basics in ColdFusion MX, and also provides code samples for SQL Server, Oracle, MSDE, and MS Access. In the next DevNet launch, Simon Horwith discusses ColdFusion transactions and rollbacks: who should use them and when, best practices, limitations and more. If you've ever considered using Stored Procedures or transactions but weren't sure how to use them in your application, don't miss these two articles.
Even if you're an old hat at ColdFusion and think there's nothing else for you to learn, there are always new areas to venture into. Macromedia instructor Matt Boles writes about RIAs and Databases, starting you on the road of using databases with your Rich Internet Applications. He provides the ActionScript and ColdFusion component code that you need to enable the interaction between Macromedia Flash and the database.
Simple. Powerful. Flexible.
The name may have changed (however slightly),
the code base may have changed, and there
are more features than ever before, but
really, some things never change. Database
interaction is still the heart and soul
of ColdFusion—make the most of it!
About the author
Debbie Dickerson is a Senior Support Engineer and has been working with ColdFusion since joining Macromedia in 1999. She is currently the TechNote Editor and Coordinator for the ColdFusion Support Center.
Submit feedback on our tutorials, articles, and sample applications.